/*
 * This class holds the information about the CD
 */
package edu.iyte.ceng431.hw03.cdplayer.model;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.Observable;

/**
 *
 * @author CUNEYT
 */
public class CD extends Observable {

    protected ArrayList<Track> tracks;
    protected String title;

    public CD(ArrayList<Track> tracks, String title) {
        this.title = title;
        this.tracks = tracks;
    }


    //Calculates the total length of the CD and returns the time in the format hh:mm:ss
    public String calculateTotalLength() {
        int result = 0, hour = 0, minute = 0;
        StringBuilder time = new StringBuilder();
        Iterator<Track> it = this.tracks.iterator();
        while (it.hasNext()) {
            result += it.next().getLength();
        }
        time.append(hour = result / 3600);
        time.append(":");
        time.append(minute = (result - hour * 3600) / 60);
        time.append(":");
        time.append((result - hour * 3600 - minute * 60));
        return time.toString();
    }

    /**
     * @return the tracks
     */
    public ArrayList<Track> getTracks() {
        return tracks;
    }

    /**
     * @param tracks the tracks to set
     */
    public void setTracks(ArrayList<Track> tracks) {
        this.tracks = tracks;
    }

    /**
     * @return the title
     */
    public String getTitle() {
        return title;
    }

    /**
     * @param title the title to set
     */
    public void setTitle(String title) {
        this.title = title;
    }
}
